package cn.java86.test2;

import cn.java86.dao.GradeDao;
import cn.java86.entity.Grade;
import cn.java86.entity.Student;
import cn.java86.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

/**
 * @author oldliu
 * @since 1.0
 */
public class Level2Cache {
    public static void main(String[] args) {

        for (int i = 0; i <= 6; i++) {
            System.out.println("??????????????????");
            m1(i + 1);
        }
//        add();
//        System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!");
//        m1();

    }

    public static void add() {
        SqlSession s = MybatisUtil.get();
        GradeDao mapper = s.getMapper(GradeDao.class);
        Grade g = new Grade();
        g.setGname("初四");
        mapper.add(g);
        s.commit();
        MybatisUtil.close(s);
    }

    public static void m1(long id) {
        SqlSession s = MybatisUtil.get();
        GradeDao mapper = s.getMapper(GradeDao.class);
        Grade grade = mapper.get(id);
        System.out.println("年级信息如下:");
        System.out.println(grade);
        if (grade != null) {
            System.out.println("学生信息如下:");
            for (Student st : grade.getStus()) {
                System.out.println(st);
            }
        }

        MybatisUtil.close(s);
    }
}
